﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AsynchronousTestSynchronizationContext.cs" company="JDML Consulting Ltd.">
//   Copyright 2011 Photon Project - http://photon.codeplex.com
// </copyright>
// <summary>
//   Defines the AsynchronousTestSynchronizationContext type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Photon.Testing.Threading
{
    using System.Threading;

    public class AsynchronousTestSynchronizationContext : SynchronizationContext
    {
        private readonly IAsynchronousTestDispatcher _dispatcher;

        public AsynchronousTestSynchronizationContext(IAsynchronousTestDispatcher dispatcher)
        {
            _dispatcher = dispatcher;
        }

        public override void Post(SendOrPostCallback d, object state)
        {
            _dispatcher.SendOrPost(() => d(state));
        }
    }
}